package cn.hj.config;

import javax.servlet.*;
import java.io.IOException;
import java.util.EnumSet;

public class MyFilter implements WebInitializerInterface,Filter {
    @Override
    public void init(ServletContext sc) {

        FilterRegistration.Dynamic myFilter = sc.addFilter("myFilter", new MyFilter());
        myFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("MyFilter..初始化");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("doFilter方法。。。");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        System.out.println("MyFilter..销毁");

    }
}
